using System;
using System.Collections.Generic;
using System.Text;
using FireStarterModeller.BO;
using FireStarterModeller.Test.BO;
using FireStarterModeller.UI;
using Habanero.Base;
using Habanero.UI.Base;
using Habanero.UI.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestUniqueConstraintPropertyInfosControl 
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();

        }
        [Test]
        public void TestConstruction()
        {
            //---------------Set up test pack-------------------

            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            UniqueConstraintPropertyInfosControl control = new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());
            //---------------Test Result -----------------------
            Assert.IsInstanceOfType(typeof(UserControlWin), control);
            Assert.IsInstanceOfType(typeof(IFormControl), control);
            Assert.AreNotEqual(0, control.Controls.Count);
            IBOGridAndEditorControl gridAndBOEditorControl = UITestUtils.GetGridAndBOEditorControl(control);
            Assert.IsNotNull(gridAndBOEditorControl, "Should have a Grid and BO Editor Control");
        }

        [Test]
        public void TestSetUniqueConstraintInfo_LoadsUniqueConstraintPropertyInfos()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraint info = TestUtils.CreateSavedUniqueConstraintInfoWithProperties();
            UniqueConstraintPropertyInfosControl control = new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());
            IBOGridAndEditorControl gridAndBOEditorControl = UITestUtils.GetGridAndBOEditorControl(control);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            control.UniqueConstraint = info;
            //---------------Test Result -----------------------
            Assert.AreSame(info, control.UniqueConstraint);
            Assert.AreEqual(info.UniqueConstraintProperties, control.UniqueConstraintPropertyInfos);
            IBusinessObjectCollection gridCollection = gridAndBOEditorControl.GridControl.Grid.BusinessObjectCollection;
            Assert.AreSame(gridCollection, control.UniqueConstraintPropertyInfos);
        }

        [Test]
        public void TestSetBusinessObject_ToNull_LoadsEmptyCollection()
        {
            //---------------Set up test pack-------------------
            UniqueConstraintPropertyInfosControl control = new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            control.UniqueConstraint = null;
            //---------------Test Result -----------------------
            Assert.AreEqual(0, control.UniqueConstraintPropertyInfos.Count);
        }

        [Test]
        public void TestDisabledAtCreation()
        {
            //---------------Execute Test ----------------------
            UniqueConstraintPropertyInfosControl control =
                new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());
            //---------------Test Result -----------------------

            Assert.IsFalse(control.Enabled);
        }

        [Test]
        public void TestSetBusinessObject_EnablesControl()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraint info = TestUtils.CreateSavedUniqueConstraintInfoWithProperties();
            UniqueConstraintPropertyInfosControl control =
                new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());

            //---------------Execute Test ----------------------
            control.UniqueConstraint = info;
            //---------------Test Result -----------------------
            Assert.IsTrue(control.Enabled);
        }

        [Test]
        public void TestSetBusinessObject_ToNull_DisablesControl()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraint info = TestUtils.CreateSavedUniqueConstraintInfoWithProperties();
            UniqueConstraintPropertyInfosControl control = new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());
            control.UniqueConstraint = info;
            //---------------Execute Test ----------------------
            control.UniqueConstraint = null;
            //---------------Test Result -----------------------
            Assert.IsFalse(control.Enabled);
        }

        [Test]
        public void TestSetUniqueConstraintPropertyInfo_SetsSelectedUniqueConstraintPropertyInfo()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraint businessObject = TestUtils.CreateSavedUniqueConstraintInfoWithProperties();
            UniqueConstraintPropertyInfosControl control = new UniqueConstraintPropertyInfosControl(new ControlFactoryWin());
            IBOGridAndEditorControl gridAndBOEditorControl = UITestUtils.GetGridAndBOEditorControl(control);
            control.UniqueConstraint = businessObject;
            DMUniqueConstraintProperty info = businessObject.UniqueConstraintProperties[1];

            //---------------Execute Test ----------------------
            control.UniqueConstraintProperty = info;

            //---------------Test Result -----------------------
            Assert.AreSame(info, control.UniqueConstraintProperty);
            Assert.AreSame(info, gridAndBOEditorControl.CurrentBusinessObject);
        }
    }
}
